package org.concepts.algorithm.datastructure;

import java.util.TreeMap;

import org.junit.Assert;
import org.junit.Test;

public class TestLinkedList {

  @Test
  public void testContains() {
    LinkedList<Integer> numbers = new LinkedList<Integer>();

    Assert.assertEquals(false, numbers.contains(1));
    
    numbers.add(1);
    Assert.assertEquals(true, numbers.contains(1));
    
    numbers.add(2);
    Assert.assertEquals(true, numbers.contains(1));
    Assert.assertEquals(true, numbers.contains(2));

  }
  
  @Test
  public void bigOAdd() {
    int total = 10000000;
    TreeMap<Integer,Long> listAddTime = new TreeMap<Integer, Long>();
    for (int listCnt = 0; listCnt <= total; listCnt += 500000) {
      long startTime = System.nanoTime();
      LinkedList<Integer> list = new LinkedList<Integer>();
      for (int itemCnt = 0; itemCnt <= listCnt ; itemCnt++) {
        list.add(listCnt);
      }
      long endTime = System.nanoTime();
      listAddTime.put(listCnt, endTime - startTime);
      printTime(listAddTime);
      listAddTime.clear();
    }
  }

  private void printTime(TreeMap<Integer, Long> listAddTime) {
    for (Integer size : listAddTime.keySet()) {
      if (size % 1000 == 0) {
        double msTime = (listAddTime.get(size) / 1000000.00) ;
        System.out.println(size + "," + msTime + " ms");
      }
    }
  }
  
  
}
